package com.yunji.order.dto.cmd;

import com.yunji.order.domain.OrderDO;
import com.yunji.order.emuns.OrderStatusEnum;
import lombok.Data;

import java.util.Optional;

/**
 * @author : peter-zhu
 * @date : 2025/3/8 17:27
 * @description : TODO
 **/
@Data
public class OrderCommandDTO {
    private OrderDO orderDO;
    private OrderStatusEnum oldStatus;
    private OrderStatusEnum newStatus;

    public OrderCommandDTO() {
    }

    public OrderCommandDTO(OrderDO orderDO, OrderStatusEnum newStatus) {
        this.newStatus = newStatus;
        this.orderDO = orderDO;
    }

    public OrderStatusEnum getOldStatus() {
        Optional.ofNullable(orderDO).orElseThrow(() -> new RuntimeException("订单为null"));
        return OrderStatusEnum.fromCode(orderDO.getOrderStatus());
    }
}
